package com.free.compilation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.free.compilation.service.ZoneCompilationChapterService;
import com.free.compilation.domain.ZoneCompilationChapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.free.common.log.annotation.Log;
import com.free.common.log.enums.BusinessType;
import com.free.common.security.annotation.RequiresPermissions;
import com.free.common.core.web.controller.BaseController;
import com.free.common.core.web.domain.AjaxResult;
import com.free.common.core.utils.poi.ExcelUtil;
import com.free.common.core.web.page.TableDataInfo;

/**
 * 章节记录Controller
 *
 * @author free
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/chapter")
public class ZoneCompilationChapterController extends BaseController {
    @Autowired
    private ZoneCompilationChapterService zoneCompilationChapterService;

    /**
     * 查询章节记录列表
     */
    @RequiresPermissions("note:chapter:list")
    @GetMapping("/list")
    public TableDataInfo list(ZoneCompilationChapter zoneCompilationChapter) {
        startPage();
        List<ZoneCompilationChapter> list = zoneCompilationChapterService.selectZoneCompilationChapterList(zoneCompilationChapter);
        return getDataTable(list);
    }

    /**
     * 导出章节记录列表
     */
    @RequiresPermissions("note:chapter:export")
    @Log(title = "章节记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZoneCompilationChapter zoneCompilationChapter) {
        List<ZoneCompilationChapter> list = zoneCompilationChapterService.selectZoneCompilationChapterList(zoneCompilationChapter);
        ExcelUtil<ZoneCompilationChapter> util = new ExcelUtil<ZoneCompilationChapter>(ZoneCompilationChapter.class);
        util.exportExcel(response, list, "章节记录数据");
    }

    /**
     * 获取章节记录详细信息
     */
    @RequiresPermissions("note:chapter:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(zoneCompilationChapterService.selectZoneCompilationChapterById(id));
    }

    /**
     * 新增章节记录
     */
    @RequiresPermissions("note:chapter:add")
    @Log(title = "章节记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZoneCompilationChapter zoneCompilationChapter) {
        return success(zoneCompilationChapterService.insertZoneCompilationChapter(zoneCompilationChapter));
    }    /**
     * 新增章节记录
     */
    @RequiresPermissions("note:chapter:add")
    @Log(title = "章节记录", businessType = BusinessType.INSERT)
    @PostMapping("batchAddChapter")
    public AjaxResult batchAddChapter(@RequestBody List<ZoneCompilationChapter> zoneCompilationChapter) {
        return toAjax(zoneCompilationChapterService.batchUpdateChapter(zoneCompilationChapter));
    }

    /**
     * 修改章节记录
     */
    @RequiresPermissions("note:chapter:edit")
    @Log(title = "章节记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZoneCompilationChapter zoneCompilationChapter) {
        return toAjax(zoneCompilationChapterService.updateZoneCompilationChapter(zoneCompilationChapter));
    }

    /**
     * 删除章节记录
     */
    @RequiresPermissions("note:chapter:remove")
    @Log(title = "章节记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(zoneCompilationChapterService.deleteZoneCompilationChapterByIds(ids));
    }
}
